//
//  SCBarButtonItemView.m
//  Navigation
//
//  Created by dangshuai on 2019/2/21.
//  Copyright © 2019 dangshuai. All rights reserved.
//

#import "SCBarButtonItemView.h"

@implementation SCBarButtonItemView

//- (void)willMoveToSuperview:(UIView *)newSuperview {
//    if (newSuperview) {
//        if (@available(iOS 11.0, *)) {
//            [newSuperview.rightAnchor constraintEqualToAnchor:newSuperview.superview.rightAnchor].active = YES;
//        }
//    }
//}

- (void)addTouchUpInsideBlcok:(TouchUpInsideBlock)block {
    _upInsideBlock = block;
    [self addTarget:self action:@selector(touchUpInsideEvent) forControlEvents:UIControlEventTouchUpInside];
}

- (void)touchUpInsideEvent {
    !_upInsideBlock ?: _upInsideBlock();
}

- (UIFont *)titleFont {
    if (!_titleFont) {
        NSDictionary *dic = [[UIBarButtonItem appearance] titleTextAttributesForState:0];
        UIFont *font = [dic objectForKey:NSFontAttributeName];
        if (!font) {
            font = [UIFont systemFontOfSize:15];
        }
        _titleFont = font;
    }
    return _titleFont;
}

- (UIEdgeInsets)alignmentRectInsets {
    if (UIEdgeInsetsEqualToEdgeInsets(self.alignmentRectInsetsOverride, UIEdgeInsetsZero)) {
        return super.alignmentRectInsets;
    } else {
        return self.alignmentRectInsetsOverride;
    }
}

@end
